package refactoredBankSystem;
import java.util.Vector;

/**
 * The Bank class.
 * @author (refactorers) Sagar Kamboj, Yong Yu Wang
 *
 */
public class Bank 
{
	/**
	 * The name of this bank.
	 */
	private String fName;

	/**
	 * The checking accounts in the bank.
	 */
	private Vector<CheckingAccount> fCheckingAccounts;
	
	/**
	 * The savings accounts in the bank.
	 */
	private Vector<SavingsAccount> fSavingAccounts;
	
	
	/**
	 * Creates an empty bank account of the name specified.
	 * 
	 * @param the_name: the banks name.
	 */
	public Bank(String name)
	{
		fCheckingAccounts = new Vector<CheckingAccount>();
		fSavingAccounts = new Vector<SavingsAccount>();
	}
	
	/**
	 * Opens a checking account.
	 * 
	 * @return the account number.
	 */
	public final int openSimpleCheckingAccount()
	{
		Customer newCustomer = new Customer("Bob Smith", "1 Main St.", "12345", "Tacoma", "USA");
		CheckingAccount newAccount = new CheckingAccount(newCustomer);
		fCheckingAccounts.add(newAccount);
		return newAccount.getAccountNumber();
	}
	
	/**
	 * Opens both a checking account and a savings account for the person.
	 * 
	 * @return the account number
	 */
	public final int openFullPackage()
	{
		Customer newCustomer = new Customer("Bob Smith", "1 Main St.", "12345", "Tacoma", "USA");
		CheckingAccount newAccount = new CheckingAccount(newCustomer);
		fCheckingAccounts.add(newAccount);
		newAccount.applyForCreditCard(newCustomer, newAccount.getAccountNumber());
		SavingsAccount newSavingsAccount = new SavingsAccount(newCustomer);
		fSavingAccounts.add(newSavingsAccount);
		@SuppressWarnings("unused")
		DebitCard newDebitCard = new DebitCard(newCustomer, newAccount);
		return newAccount.getAccountNumber();
	}
	
	/**
	 * Withdraws the amount specified, from the accountNumber passed in.
	 * 
	 * @param accountNumber of the person
	 * @param amount that is needed to be withdrawn.
	 * @return the money that is withdrawn
	 */
	public final boolean withdrawMoney(final int accountNumber, final double amount)
	{
		CheckingAccount account = new CheckingAccount(accountNumber);
		int index = fCheckingAccounts.indexOf(account);
		return fCheckingAccounts.elementAt(index).withdrawal(amount);
	}
	
	/**
	 * Gets the name of this bank.
	 * @return	the name of this bank.
	 */
	public String getName() {
		return fName;
	}
	
	/**
	 * Sets the name of this bank to a new one.
	 * @param newName the new name to set.
	 */
	public void setName(String newName) {
		fName = newName;
	}
	
}
